package com.signway.utils;

/*
 * -----------------------------------------------------------------
 * Copyright (C) 2011-2021, by your Signway, All rights reserved.
 * -----------------------------------------------------------------
 *
 * ProjectName: ds_touch_common
 *
 * Author: ZY
 *
 * Email: yong.zhou@signway.cn
 *
 * Description:
 *
 * -----------------------------------------------------------------
 * 2021/8/13 : Create UrlSplitUtils.java
 * -----------------------------------------------------------------
 */
public class UrlSplitUtils {
    /**
     * 去除url里指定的某个参数，如果清的是最后一个参数，最后截取的url会带一个&符号
     *
     * @param Url
     * @param PartName
     * @return
     */
    public static String RemoveUrlPart(String Url, String PartName) {
        PartName = PartName + "=";
        if (Url.contains(PartName)) {
            System.out.println(" " + (Url.indexOf(PartName) + PartName.length()) + " " + (Url.length() - (Url.indexOf(PartName) + PartName.length())));
            String Text = Url.substring((Url.indexOf(PartName) + PartName.length()),
                    Url.length());
            if (Text.contains("&")) {
                Text = Text.substring(Text.indexOf("&") + 1, Text.length() - (Text.indexOf("&")) - 1);
            } else {
                Text = "";
            }
            return Url.substring(0, Url.indexOf(PartName)) + Text;
        } else {
            return Url;
        }
    }

    public static String RemoveUrlPart(String url) {
        int i = url.indexOf("?");
        String substring = url.substring(0, i+1);

        int i1 = substring.lastIndexOf("/");
        String substring1 = substring.substring(i1+1, i);
        return substring1;
    }
}
